
#include "stdafx.h"


#include <windows.h>
#include <commctrl.h>
#include <mmsystem.h>

#include "miscutil.h"
#include "SmpTst.h"
#include "CmdLnPars.h"


_tstring gWAV_strSndFile;
bool gWAV_fLoop;

extern "C" void wav_playsnd(SmpTstFunCntx* pv)
{
	if(gWAV_strSndFile.empty())
	{
		SMPTST_RSLT_RETURN(pv, FALSE, (TEXT("no wav_snd_file to play!"), gWAV_strSndFile.c_str(), GetLastError()));
	}

	DWORD fdwSound=SND_ASYNC|SND_FILENAME;
	if(gWAV_fLoop)
	{
		fdwSound|=SND_LOOP;
	}

	if(!PlaySound(gWAV_strSndFile.c_str(), NULL, fdwSound))
	{
		SMPTST_RSLT_RETURN(pv, FALSE, (TEXT("PlaySound faild:%d!"), GetLastError()));
	}
	SMPTST_RSLT_RETURN(pv, TRUE, (TEXT("PlaySound:%s successed!"), gWAV_strSndFile.c_str()));
}

extern "C" void wav_stopsnd(SmpTstFunCntx* pv)
{
	if(!PlaySound(NULL, NULL, 0))
	{
		SMPTST_RSLT_RETURN(pv, FALSE, (TEXT("stop PlaySound faild:%d!"), GetLastError()));
	}
	SMPTST_RSLT_RETURN(pv, TRUE, (TEXT("stop PlaySound successed!")));
}


SMPTST_GROUP(WAVE_TST, TEXT("WAVE TEST"));
	SMPTST_SUB_FUNCTION(wav_playsnd, TEXT("PlaySound(wav_snd_file)"), WAVE_TST);
	SMPTST_SUB_FUNCTION(wav_stopsnd, TEXT("stop_PlaySnd"), WAVE_TST);

CMDLINE_INIT_NAME_VAL(_T("_wav"), _tstring, gWAV_strTstOptions, _T(""), TEXT("USE \"/tst_var:wav_\" TO LIST WAVE TEST OPTIONS\r\n"), FALSE);
CMDLINE_INIT_EXT_NAME_VAL(_T("wav_snd_file"), _tstring, gWAV_strSndFile, TEXT(":FILE_NAME of wav_playsnd\r\n"), FALSE);
CMDLINE_INIT_EXT_NAME_VAL(_T("wav_snd_loop"), bool, gWAV_fLoop, TEXT("loop playsound\r\n"), FALSE);

